<template>
  <el-container class="layout-container">
    <el-aside width="240px" class="aside-card">
      <div class="aside-header">
        <span class="aside-title">坤哥物流 - 用户端</span>
        <el-dropdown @command="handleCommand">
          <span class="user-info">
            {{ userInfo.username }}
            <el-icon><ArrowDown /></el-icon>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item command="profile">个人信息</el-dropdown-item>
              <el-dropdown-item command="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
      <el-menu
        :default-active="activeMenu"
        class="el-menu-vertical"
        router
      >
        <el-menu-item index="/user/home">
          <el-icon><HomeFilled /></el-icon>
          <span>首页</span>
        </el-menu-item>
        <el-menu-item index="/user/orders">
          <el-icon><List /></el-icon>
          <span>我的订单</span>
        </el-menu-item>
        <el-menu-item index="/user/address">
          <el-icon><Location /></el-icon>
          <span>收货地址</span>
        </el-menu-item>
        <el-menu-item index="/user/profile">
          <el-icon><User /></el-icon>
          <span>个人信息</span>
        </el-menu-item>
        <el-menu-item index="/user/ditu">
          <el-icon><User /></el-icon>
          <span>地图位置</span>
        </el-menu-item>
        <el-menu-item index="/user/index">
          <el-icon><User /></el-icon>
          <span>智能AI</span>
        </el-menu-item>
      </el-menu>
    </el-aside>
    <el-main>
      <router-view></router-view>
    </el-main>
  </el-container>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { HomeFilled, List, Location, User, ArrowDown } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
import {useUserStore} from "@/pinia/index.js";

const router = useRouter()
const route = useRoute()
var user = useUserStore();
// 模拟用户信息
const userInfo = ref({
  username: user.getUsername,
  phone: '13800138000'
})

const activeMenu = computed(() => route.path)

const handleCommand = (command) => {
  if (command === 'logout') {
    ElMessage.success('退出成功')
    router.push('/login')
  } else if (command === 'profile') {
    router.push('/user/profile')
  }
}
</script>

<style scoped>
.layout-container {
  height: 100vh;
  min-width: 1200px;
  display: flex;
  flex-direction: row;
  background: #f5f7fa;
}

.aside-card {
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 4px 24px 0 rgba(0,0,0,0.08);
  margin: 24px 0 24px 24px;
  display: flex;
  flex-direction: column;
  padding-bottom: 24px;
  width: 240px !important;
}

.aside-header {
  background: #409EFF;
  color: #fff;
  border-radius: 18px 18px 0 0;
  padding: 28px 20px 18px 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.aside-title {
  font-size: 1.2rem;
  font-weight: bold;
  letter-spacing: 1px;
}

.user-info {
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 1rem;
}

.el-menu-vertical {
  border-right: none;
  background: transparent;
  margin-top: 16px;
}

.el-main {
  background: #f5f7fa;
  padding: 32px 32px 32px 0;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  box-sizing: border-box;
}

@media (max-width: 1400px) {
  .layout-container {
    min-width: 900px;
  }
  .aside-card {
    margin-left: 8px;
  }
}
</style> 